package com.server.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.server.authority.Login;
import com.server.common.base.SessionData;
import com.server.service.IMngBaseService;
import com.server.service.IMsgManagementService;
import com.server.web.SessionUtil;

@Controller
@RequestMapping("mngindex")
public class MngIndexController{
	
	@Autowired
	private IMngBaseService mngBaseService;
	@Autowired
	private IMsgManagementService msgManagementService;
	
	@Login
	@RequestMapping("")
	public ModelAndView index(HttpServletRequest request){
		/*
		 * 记录Http地址
		 */
		String requestUrl = msgManagementService.getRequestUrl();
		if (StringUtils.isEmpty(requestUrl)) {
			String requestStr = request.getRequestURL().toString().replace("mngindex", "");
			msgManagementService.setRequestUrl(requestStr);
		}
		
		String adminUser = SessionUtil.getStringAttri(request, SessionData.nameKey_mng);
		String uuid = SessionUtil.getStringAttri(request, SessionData.uuidKey_mng);
		List<Map<String, Object>> menuList = mngBaseService.getMenu(adminUser);
		ModelAndView mv = new ModelAndView("mngIndex/index");
		mv.addObject("menuList",menuList);
		mv.addObject("nickname", adminUser);
		mv.addObject("uuid", uuid);
		return mv;
	}
	@Login
	@RequestMapping("home")
	public ModelAndView home(HttpServletRequest request){
		ModelAndView mv = new ModelAndView("mngIndex/home");
		String adminUser = SessionUtil.getStringAttri(request, SessionData.nameKey_mng);
		mv.addObject("nickname", adminUser);
		return mv;
	}
}
